Recompile when RUSTFLAGS changes
authorBrian Anderson <banderson@mozilla.com>
Wed, 17 Feb 2016 01:14:49 +0000 (01:14 +0000)
committerBrian Anderson <banderson@mozilla.com>
Wed, 16 Mar 2016 16:49:22 +0000 (16:49 +0000)
src/cargo/ops/cargo_rustc/fingerprint.rs
tests/test_cargo_compile.rs

index 837b14bc113356c8ff759e348c5d39b5ee8b7351..8195ee378264aa6dbe67b2e13c54a1d879659f7e 100644 (file)
@@ -111,6 +111,7 @@ pub struct Fingerprint {
     deps: Vec<(String, Arc<Fingerprint>)>,
     local: LocalFingerprint,
     memoized_hash: Mutex<Option<u64>>,
+    rustflags: Vec<String>,
 }
 
 #[derive(RustcEncodable, RustcDecodable, Hash)]
@@ -160,6 +161,9 @@ impl Fingerprint {
         if self.profile != old.profile {
             bail!("profile configuration has changed")
         }
+        if self.rustflags != old.rustflags {
+            return Err(internal("RUSTFLAGS has changed"))
+        }
         match (&self.local, &old.local) {
             (&LocalFingerprint::Precalculated(ref a),
              &LocalFingerprint::Precalculated(ref b)) => {
@@ -202,8 +206,9 @@ impl hash::Hash for Fingerprint {
             ref deps,
             ref local,
             memoized_hash: _,
+            ref rustflags,
         } = *self;
-        (rustc, features, target, profile, deps, local).hash(h)
+        (rustc, features, target, profile, deps, local, rustflags).hash(h)
     }
 }
 
@@ -222,6 +227,7 @@ impl Encodable for Fingerprint {
                     (a, b.hash())
                 }).collect::<Vec<_>>().encode(e)
             }));
+            try!(e.emit_struct_field("rustflags", 6, |e| self.rustflags.encode(e)));
             Ok(())
         })
     }
@@ -252,9 +258,11 @@ impl Decodable for Fingerprint {
                             features: String::new(),
                             deps: Vec::new(),
                             memoized_hash: Mutex::new(Some(hash)),
+                            rustflags: Vec::new(),
                         }))
                     }).collect()
-                }
+                },
+                rustflags: try!(d.read_struct_field("rustflags", 6, decode)),
             })
         })
     }
@@ -346,6 +354,7 @@ fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
         deps: deps,
         local: local,
         memoized_hash: Mutex::new(None),
+        rustflags: cx.rustflags_args(unit),
     });
     cx.fingerprints.insert(*unit, fingerprint.clone());
     Ok(fingerprint)
@@ -425,6 +434,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
         deps: Vec::new(),
         local: local,
         memoized_hash: Mutex::new(None),
+        rustflags: Vec::new(),
     };
     let compare = compare_old_fingerprint(&loc, &fingerprint);
     log_compare(unit, &compare);
index d51c51d783d346ba1607cee3c656234b3a1f14f5..9530e9417840783ad1104fe84a35a34d86ac227a 100644 (file)
@@ -2396,3 +2396,53 @@ test!(rustflags_plugin_dep_with_target {
                 .arg("--target").arg(host),
                 execs().with_status(0));
 });
+
+test!(rustflags_recompile {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+        "#)
+        .file("src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build"),
+                execs().with_status(0));
+    // Setting RUSTFLAGS forces a recompile
+    assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
+                execs().with_status(101));
+});
+
+test!(rustflags_recompile2 {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+        "#)
+        .file("src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
+                execs().with_status(0));
+    // Setting RUSTFLAGS forces a recompile
+    assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"),
+                execs().with_status(101));
+});
+
+test!(rustflags_no_recompile {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+        "#)
+        .file("src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
+                execs().with_status(0));
+    assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"),
+                execs().with_stdout("").with_status(0));
+});